package com.yc.cloud.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yc.cloud.entity.HwCameraSnapshotRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalDateTime;

/**
 * <p>
 * 摄像头抓图记录表 Mapper 接口
 * </p>
 *
 * @author kinggu
 * @since 2025-10-10
 */
@Mapper
public interface HwCameraSnapshotRecordMapper extends BaseMapper<HwCameraSnapshotRecord> {

    /**
     * 获取摄像头最近一次抓图记录
     */
    default HwCameraSnapshotRecord selectLatestByCameraId(Long cameraId) {
        return this.selectOne(
            new QueryWrapper<HwCameraSnapshotRecord>()
                .eq(HwCameraSnapshotRecord.CameraId, cameraId)
                .eq(HwCameraSnapshotRecord.Deleted, false)
                .orderByDesc(HwCameraSnapshotRecord.CREATE_TIME) // Use create_time instead of snapshotTime
                .last("LIMIT 1")
        );
    }
    
    /**
     * 统计摄像头抓图总数
     */
    default Long countByCameraId(Long cameraId) {
        return this.selectCount(
            new QueryWrapper<HwCameraSnapshotRecord>()
                .eq(HwCameraSnapshotRecord.CameraId, cameraId)
                .eq(HwCameraSnapshotRecord.Deleted, false)
        );
    }
    
} 